package mylist
{
	//import com.Cookies;
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.KeyboardEvent;
	import flash.net.FileFilter;
	import flash.net.FileReferenceList;
	import mylist.*;
	
	/**
	 * 中兴项目client document class
	 * ...
	 * @author db0@qq.com
	 */
	//[SWF(width=600,height=700,backgroundColor=0)]
	
	public class listMain extends Sprite
	{
		//public static var showSmall:ShowSmall = new ShowSmall();
		public static var multiUploadBtns:MultiUploadBtns = new MultiUploadBtns();
		
		private var fileList:FileReferenceList = new FileReferenceList();
		public static var main:listMain;
		
		public function listMain()
		{
			//logs.adds(1<<2);
			//trace(uint.MAX_VALUE);
			
			if (main)
				return;
			main = this;
			DragItem.willSend = true;
			
			[Embed(source="../asset/phonebg.png")]
			var bg:Class;
			addChild(new bg());
			
			addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function keys(e:KeyboardEvent):void
		{
			logs.adds(String.fromCharCode(e.keyCode));
			switch (String.fromCharCode(e.keyCode))
			{
				case "C": //clear all the photo in the viewlist
					listMain.clearSelected();
					break;
				case "S": //browse the file system to add photo to the viewlist
					browses();
					break;
				case "H": //logs
					stage.addChild(new logs);
					logs.txt.visible = !logs.txt.visible;
					break;
				case "P": //photo
					if(MyCam.main)MyCam.main.savepic(null);
					break;
				case "K": //add a random bmp to the viewlist
					ViewList.main.addChilds(new Bitmap(new BitmapData(8192 * Math.random() + 2, 2048 * Math.random() + 2, false, 0xffffffff * Math.random())));
					break;
				default: 
			}
		}
		
		public function browses(e:Event = null):void
		{
			fileList.browse([new FileFilter("images", "*.jpg;*.jpeg;*.png;*.gif")]);
			fileList.addEventListener(Event.SELECT, selected);
		}
		
		private function selected(e:Event):void
		{
			//trace(fileList.fileList);
			var i:int = 0;
			while (i < fileList.fileList.length)
			{
				FileItem.push(fileList.fileList[i]);
				++i;
			}
			
			//ViewList.main.y = ViewList.origY;
			new Loaders();
		}
		
		//public static var bigborder:BigBirdor = new BigBirdor();
		
		private function init(e:Event):void
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			stage.addEventListener(KeyboardEvent.KEY_UP, keys);
			
			//stage.displayState = StageDisplayState.FULL_SCREEN;
			//addChild(new Bitmap(new BitmapData(stage.stageWidth, stage.stageHeight, false, 0)));
			
			//stage.addChild(new logs);
			stage.addChild(multiUploadBtns);
			stage.addChild(new ViewList);
			//addChild(showSmall);
		
		}
		
		static public function clearSelected():void
		{
			logs.adds("clear list");
			ViewList.main.clears();
		}
	
	}

}